﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Job.Core;
using Job.Core.Module;
using Job.Core.Collections;

namespace Job.Core
{
    //指定此类可以被序列化
    [Serializable]
    public class BaseModel<TModel> : Business<Int32, TModel>
        where TModel : Business<Int32, TModel>, new()
    {
        /// <summary>
        /// 
        /// </summary>
        public BaseModel() { }

        #region Overrides

        /// <summary>
        /// 
        /// </summary>
        protected override TModel DataLoad(Int32 id)
        {
            return Opreation().GetModel(id);
        }

        /// <summary>
        /// 必须由子类完成重写
        /// </summary>
        protected override bool DataUpdate()
        {
            //return Opreation().Update(this);
            return false;
            // return BaseInstanceDAL<Int32, TModel>.Instance().Update(this);
        }

        /// <summary>
        /// 必须由子类完成重写
        /// </summary>
        protected override bool DataCreate()
        {
            return false;
            // return Opreation().Add(this);
        }

        /// <summary>
        /// 
        /// </summary>
        protected override bool DataDelete()
        {
            return Opreation().Delete(this.KeyId) > 0;
        }

        /// <summary>
        /// 
        /// </summary>
        protected override SearchResult<TModel> DataSearch(SearchQuery Query)
        {
            return Opreation().GetResult(Query);
        }


        /// <summary>
        /// 有效性验证。
        /// </summary>
        protected override void ValidationRules(DataAction action)
        {
            base.ValidationRules(action);
            if (action == DataAction.Delete) return;

            //AddRule(string.IsNullOrEmpty(this.AdName), new RuleViolation("AdName", "广告名称为必填项。"));

            //AddRule(string.IsNullOrEmpty(this.Email), new RuleViolation("Email", "邮件地址为必填项。"));
            //AddRule(!VerificationHelper.IsEmail(this.Email), new RuleViolation("Email", "邮件地址格式不正确。"));
        }


        #endregion
    }

}
